const app = getApp()
Page({
  data: {
    showConfirmDialog: false,
    showChangeStateDialog: false,
    id: "",
    reason: "",
    repairInfo: {},
    userType: 0,
  },

  onLoad(option) {
    if (option.id) {
      this.setData({
        id: option.id,
      })
      this.getRepairInfo(option.id)
    }
    let zzstatus = app.globalData.session.zzstatus
    this.setData({
      userType: zzstatus
    })
  },
  onBack() {
    wx.navigateBack();
  },
  getRepairInfo() {
    app.axios('workOrder', {
      op: 'ajaxWorkOrderWxsmView',
      id: this.data.id
    }).then(res => {
      if (res.code && res.item && res.item.content) {
        res.item.info = app.parseJSONString(res.item.content)
        res.item.hasMaterial = res.item.info.lms && res.item.info.lms.length ? true : false
      }
      this.setData({
        repairInfo: res.item
      })
    })
  },
  onDialogConfirm() {
    if (this.data.userType == 1) {
      app.axios('workOrder', {
        op: 'ajaxWoowxsmPayUp',
        zwxeid: this.data.repairInfo.id,
        zwid: this.data.repairInfo.woid,
        content: this.data.reason,
      }).then(res=>{
        if(res.code){
          wx.showToast({
            title:'状态变更成功'
          })
          setTimeout(() => {
            wx.navigateBack()
          }, 500);
        }
      })
    }
  },
  onPay() {
    console.log("支付");
    this.setData({
      showConfirmDialog: true
    })
    // 调用支付接口
    wx.requestPayment({
      timeStamp: "123456789",
      nonceStr: "abcdefg",
      package: "prepay_id=123456789",
      signType: "MD5",
      paySign: "123456789",
      success: (res) => {
        console.log("支付成功", res);
      },
      fail: (res) => {
        console.log("支付失败", res);
      },
    });
  },

  changeState() {
    this.setData({
      reason: "",
      showChangeStateDialog: true,
    });
  },
});
